package eu.vranckaert.workRegistrationWidget.activities;

import android.os.Bundle;
import android.preference.*;
import eu.vranckaert.workRegistrationWidget.R;
import eu.vranckaert.workRegistrationWidget.util.Preferences;

/**
 * @author Dirk Vranckaert
 *         Date: 10-jun-2010
 *         Time: 15:32:10
 */
public class PreferencesActivity extends PreferenceActivity {
    @Override
    public void onCreate(Bundle savedInstance) {
        super.onCreate(savedInstance);

        getPreferenceManager().setSharedPreferencesName(Preferences.PREF_NAME);
        createPreferenceScreen();
    }

    private PreferenceScreen createPreferenceScreen() {
        PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
        setPreferenceScreen(root);

        CheckBoxPreference gpsUsageAllowed = new CheckBoxPreference(this);
        gpsUsageAllowed.setDefaultValue(Preferences.KEY_DEFAULT_GPS_USAGE_ALLOWED);
        gpsUsageAllowed.setKey(Preferences.KEY_GPS_USAGE_ALLOWED);
        gpsUsageAllowed.setTitle(R.string.prefGpsUsageAllowedTitle);
        gpsUsageAllowed.setSummaryOff(R.string.prefGpsUsageAllowedSummaryOff);
        gpsUsageAllowed.setSummaryOn(R.string.prefGpsUsageAllowedSummaryOn);
        root.addPreference(gpsUsageAllowed);

        CheckBoxPreference gpsLastKnownLocationAllowed = new CheckBoxPreference(this);
        gpsLastKnownLocationAllowed.setDefaultValue(Preferences.KEY_DEFAULT_LAST_KNOWN_LOCATION_ALLOWED);
        gpsLastKnownLocationAllowed.setKey(Preferences.KEY_LAST_KNOWN_LOCATION_ALLOWED);
        gpsLastKnownLocationAllowed.setTitle(R.string.prefLastKnownLocationAllowedTitle);
        gpsLastKnownLocationAllowed.setSummaryOff(R.string.prefLastKnownLocationAllowedSummaryOff);
        gpsLastKnownLocationAllowed.setSummaryOn(R.string.prefLastKnownLocationAllowedSummaryOn);
        root.addPreference(gpsLastKnownLocationAllowed);
        gpsLastKnownLocationAllowed.setDependency(Preferences.KEY_GPS_USAGE_ALLOWED);

        ListPreference gpsLookupTimeout = new ListPreference(this);
        gpsLookupTimeout.setKey(Preferences.KEY_GPS_LOOKUP_TIMEOUT);
        gpsLookupTimeout.setDefaultValue(Preferences.KEY_DEFAULT_GPS_LOOKUP_TIMEOUT);
        gpsLookupTimeout.setTitle(R.string.prefGpsTimeoutTitle);
        gpsLookupTimeout.setSummary(R.string.prefGpsTimeoutSummary);
        gpsLookupTimeout.setEntries(R.array.prefGpsTimeoutList);
        gpsLookupTimeout.setEntryValues(R.array.prefGpsTimeoutListValues);
        root.addPreference(gpsLookupTimeout);
        gpsLookupTimeout.setDependency(Preferences.KEY_GPS_USAGE_ALLOWED);

        PreferenceScreen advanced = getPreferenceManager().createPreferenceScreen(this);
        advanced.setTitle(R.string.prefAdvanced);
        advanced.setSummary(R.string.prefAdvancedSummary);

        EditTextPreference exportFileName = new EditTextPreference(this);
        exportFileName.setDefaultValue(Preferences.KEY_DEFAULT_FILE_EXPORT_NAME);
        exportFileName.setKey(Preferences.KEY_FILE_EXPORT_NAME);
        exportFileName.setTitle(R.string.prefExportFileNameTitle);
        exportFileName.setSummary(R.string.prefExportFileNameSummary);
        advanced.addPreference(exportFileName);

        EditTextPreference exportFileCSVSeparator = new EditTextPreference(this);
        exportFileCSVSeparator.setDefaultValue(Preferences.KEY_DEFAULT_FILE_EXPORT_CSV_SEPARATOR);
        exportFileCSVSeparator.setKey(Preferences.KEY_FILE_EXPORT_CSV_SEPARATOR);
        exportFileCSVSeparator.setTitle(R.string.prefExportFileCsvSeparatorTitle);
        exportFileCSVSeparator.setSummary(R.string.prefExportFileCsvSeparatorSummary);
        advanced.addPreference(exportFileCSVSeparator);

        root.addPreference(advanced);

        return root;
    }
}
